<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('商户修改注册地址')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-merchantInfo-updateAddress">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">商户编号：</label>
                <div class="col-sm-8">
                    <input type="text" name="merno" th:value="${merchantInfo.merno}" class="form-control" readonly/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">商户名称：</label>
                <div class="col-sm-8">
                    <input type="text" name="merNameNo" th:value="${merchantInfo.merName}" class="form-control" readonly/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">注册地址：</label>
                <div class="col-sm-2" style="width: 120px;">
                    <select id="province" name="province"  onchange="javascript:window.province('p')" class="province form-control m-b" required>
                        <option value="">请选择</option>
                        <option th:each="p:${pList}" th:text="${p.areaName}" th:value="${p.areaCode}"  th:selected="${p.areaCode} eq ${province}"></option>
                    </select>
                </div>
                <div class="col-sm-2" style="width: 120px;">
                    <select id="city" name="city" onchange="javascript:window.province('c')" class="city form-control m-b" required>
                        <option value="">请选择</option>
                        <option th:each="c:${cList}" th:text="${c.areaName}" th:value="${c.areaCode}" th:selected="${c.areaCode} eq ${city}"></option>
                    </select>
                </div>
                <div class="col-sm-2" style="width: 120px;">
                    <select id="area" name="area" onchange="javascript:window.province('a')" class="area form-control m-b" required>
                        <option value="">请选择</option>
                        <option th:each="a:${aList}" th:text="${a.areaName}" th:value="${a.areaCode}" th:selected="${a.areaCode} eq ${area}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">详细地址：</label>
                <div class="col-sm-8">
                    <input type="text" name="merAddress" th:value="${merchantInfo.merAddress}" class="form-control" required/>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "merchantInfo/merchantInfo";
        $("#form-merchantInfo-updateAddress").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/updateAddress", $('#form-merchantInfo-updateAddress').serialize());
            }
        }
        /**
         *
         * @param type 传入 省 p 市 c 区 a
         */
        function province(type) {
            var url = ctx + "area/area/list"; //获取地址信息
            if (type == 'p'){  //联动市
                if($("#province").find("option:selected").val() == ''){
                    defaultOption("city","请选择");
                    defaultOption("area","请选择");
                } else {
                    $.post(url,{'parentId':$("#province").val(),'areaType':'1'},function(result){
                        if (result.code == '0'){
                            initSelect("city",result);
                        }
                    });
                }
            } else if (type == 'c'){  //联动县
                $.post(url,{'parentId':$("#city").val(),'areaType':'2'},function(result){
                    if (result.code == '0',result){
                        initSelect("area",result);
                    }
                });
            }
        }
        //初始化 select选项
        function initSelect(selectId,data) {
            //清空旧的数据
            if (selectId == 'city'){
                $("#"+selectId).empty();
                $("#area").empty();
            }else{
                $("#"+selectId).empty();
            }
            var option = '<option value="">请选择</option>';
            data.rows.forEach(function(value){
                option += "<option value='"+value.areaCode+"'>"+value.areaName+"</option>";
            });
            $("#"+selectId).append(option);
        }
        //初始化 select选项
        function defaultOption(selectId,text) {
            $("#"+selectId).empty();
            $("#"+selectId).append("<option value=''>" + text +"</option>");
        }
    </script>
</body>
</html>